home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2006 September / SAN CD 9-2006 CD-ROM 16.iso / pc / Software / Network Telescope Control / NTC-Setup.Exe / Source / ntc_client_network.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2006-03-24  |  19.3 KB  |  932 lines

  1. unit ntc_client_network;
  2. {
  3.     Copyright (C) 2004 - 2006 Andrew Sprott
  4.  
  5.     http://astronomy.crysania.co.uk
  6.     astro@trefach.co.uk
  7.  
  8.     This program is free software; you can redistribute it and/or
  9.     modify it under the terms of the GNU General Public License
  10.     as published by the Free Software Foundation; either version 2
  11.     of the License, or (at your option) any later version.
  12.  
  13.     This program is distributed in the hope that it will be useful,
  14.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16.     GNU General Public License for more details.
  17.  
  18.     You should have received a copy of the GNU General Public License
  19.     along with this program; if not, write to the Free Software
  20.     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. }
  22.  
  23. interface
  24.  
  25. uses
  26.     Windows,
  27.     Messages,
  28.     SysUtils,
  29.     Variants,
  30.     Classes,
  31.     Graphics,
  32.     Controls,
  33.     Forms,
  34.     Dialogs,
  35.     StdCtrls,
  36.     Mask,
  37.     Buttons,
  38.     ExtCtrls,
  39.     inifiles,
  40.  
  41.     IdBaseComponent,
  42.     IdComponent,
  43.     IdTCPConnection,
  44.     IdTCPClient,
  45.     idglobal,
  46.  
  47.     ntc_client_form;
  48.  
  49. const
  50.     { timeout intervals }
  51.     response_timeout=2000;
  52.     read_timeout=IdTimeoutInfinite;
  53.     read_fail_count=2000;
  54.     connect_timeout=1500;
  55.     max_buffer_size=240;
  56.     crlf=chr(13)+chr(10);
  57.  
  58. type
  59.     response_type_set=(
  60.         exit_ok,
  61.         exit_fail,
  62.         exit_busy,
  63.         exit_wait,
  64.         exit_ready);
  65.     response_type=set of response_type_set;
  66.  
  67.     tscope_network = class(tform)
  68.         network_panel: TPanel;
  69.         server_connect_group: TGroupBox;
  70.         connect_to_server_button: TSpeedButton;
  71.         disconnect_from_server_button: TSpeedButton;
  72.         connected_light: TMaskEdit;
  73.         server_ip_edit: TEdit;
  74.         edit_port: TEdit;
  75.         network_timer: TTimer;
  76.         scope_client: TIdTCPClient;
  77.     status_log: TMemo;
  78.         clear_log_button: TBitBtn;
  79.         messages_button: TBitBtn;
  80.         disk_button: TBitBtn;
  81.  
  82.         { form functions }
  83.         procedure formcreate(
  84.             Sender:TObject);
  85.  
  86.         procedure kill;
  87.  
  88.         procedure form_close_query(
  89.                     Sender: TObject;
  90.             var CanClose: Boolean);
  91.  
  92.         { network controls }
  93.         procedure connect_to_server;
  94.  
  95.         procedure close_network_connection;
  96.  
  97.         procedure connect_to_server_buttonClick(
  98.             Sender: TObject);
  99.  
  100.         function send_message(
  101.             message_string,
  102.             error_string:string)
  103.             :response_type;
  104.  
  105.         function send_request(
  106.             message_str,
  107.             error_str:string)
  108.             :response_type;
  109.  
  110.         function send_request_check(
  111.             message_string:string)
  112.             :response_type;
  113.  
  114.         function get_option_value(
  115.             option:string)
  116.             :string;
  117.  
  118.         function get_float(
  119.                     option:string;
  120.             var exit_result:double)
  121.             :boolean;
  122.  
  123.         function get_integer(
  124.                     option:string;
  125.             var exit_result:longint)
  126.             :boolean;
  127.  
  128.         function get_string(
  129.                     option:string;
  130.             var exit_result:string)
  131.             :boolean;
  132.  
  133.         function get_boolean(
  134.                     option:string;
  135.             var exit_result:boolean)
  136.             :boolean;
  137.  
  138.         procedure network_timerTimer(
  139.             Sender: TObject);
  140.  
  141.         procedure enable_network_timer(
  142.             timeout_interval:longint);
  143.  
  144.         procedure disconnect_from_server_buttonClick(
  145.             Sender: TObject);
  146.  
  147.         { network events }
  148.         procedure update_model_type;
  149.  
  150.         { logging }
  151.         procedure write_status_log(
  152.             e:string;
  153.             message_logging:boolean);
  154.  
  155.         procedure write_status_log_check(
  156.             e:string);
  157.  
  158.         Procedure close_log;
  159.  
  160.         Procedure write_log(
  161.             e:string);
  162.  
  163.         Procedure init_log_file(
  164.             s:string);
  165.  
  166.         { configuration }
  167.         procedure load_settings;
  168.         procedure save_settings;
  169.  
  170.         { events }
  171.         procedure FormShow(
  172.             Sender: TObject);
  173.  
  174.         procedure adjust;
  175.  
  176.         procedure hide_form;
  177.         procedure show_form;
  178.  
  179.         procedure check_activate(
  180.             Sender: TObject);
  181.  
  182.         procedure disk_buttonClick(
  183.             Sender: TObject);
  184.  
  185.         procedure messages_buttonClick(
  186.             Sender: TObject);
  187.  
  188.         procedure clear_log_buttonClick(
  189.             Sender: TObject);
  190.  
  191.     private
  192.         { Private declarations }
  193.         server_ip_address:string;
  194.         received_text:widestring;
  195.         network_connected,
  196.         server_playing,
  197.         network_timed_out:boolean;
  198.         option_names,
  199.         option_values:tstrings;
  200.         indented:integer;
  201.         { logging }
  202.         log_handle:textfile;
  203.         log_filename:string;
  204.         last_line_indented,
  205.         last_line_unindented:boolean;
  206.     public
  207.         { Public declarations }
  208.         network_enabled,
  209.         scope_connected:boolean;
  210.         form_top,
  211.         form_left:integer;
  212.         { logging }
  213.         logging:boolean;
  214.         message_logging:boolean;
  215.         { configuration }
  216.         dimensions:dimensions_record;
  217.  
  218.         { methods }
  219.         procedure check_visible_and_show_hide(
  220.             sender:tobject);
  221.     end;
  222.  
  223. var
  224.     scope_network: tscope_network;
  225.  
  226. implementation
  227.  
  228. uses
  229.     ntc_client_control,
  230.     ntc_client_info;
  231.  
  232. {$R *.dfm}
  233.  
  234.     { ----------
  235.         form stuff
  236.         ---------- }
  237.  
  238. procedure tscope_network.formcreate(
  239.     Sender:TObject);
  240. begin
  241.     network_timer.enabled:=false;
  242.     { network defaults }
  243.     network_connected:=false;
  244.     server_playing:=false;
  245.     option_names:=tstringlist.create;
  246.     option_values:=tstringlist.create;
  247.     scope_connected:=false;
  248.     connect_to_server_button.enabled:=true;
  249.     server_connect_group.enabled:=true;
  250.     indented:=0;
  251.     last_line_indented:=false;
  252.     last_line_unindented:=false;
  253.     load_settings;
  254.     if logging then
  255.         scope_network.init_log_file('ntc-client.log');
  256. end;
  257.  
  258. procedure tscope_network.kill;
  259. begin
  260.     if network_enabled then
  261.         begin
  262.             if scope_connected then
  263.                 begin
  264.                     send_request_check('disconnect');
  265.                     scope_network.scope_connected:=false;
  266.                     send_request_check('bored');
  267.                 end;
  268.             close_network_connection;
  269.         end;
  270.     option_names.free;
  271.     option_values.free;
  272. end;
  273.  
  274. procedure Tscope_network.form_close_query(
  275.             Sender: TObject;
  276.     var CanClose: Boolean);
  277. begin
  278.     canclose:=false;
  279.     visible:=false;
  280.     with dimensions do
  281.         begin
  282.             form_top:=top;
  283.             form_left:=left;
  284.         end;
  285. end;
  286.  
  287.     { -------------
  288.         network stuff
  289.         ------------- }
  290.  
  291. procedure tscope_network.connect_to_server;
  292. var
  293.     j,k:integer;
  294.     e:string;
  295.     f:boolean;
  296. begin
  297.     write_status_log_check('connect to server >>');
  298.     e:='connected to server';
  299.     f:=false;
  300.     with scope_client do
  301.         begin
  302.             Port:=StrToint(edit_Port.Text);
  303.             if port<1024 then
  304.                 begin
  305.                     e:='I needs a port greater than 1024';
  306.                     f:=true;
  307.                 end
  308.             else
  309.                 begin
  310.                     server_ip_address:=server_ip_edit.text;
  311.                     host:=server_ip_address;
  312.                     enable_network_timer(connect_timeout);
  313.                     try
  314.                         j:=0;
  315.                         k:=1;
  316.                         connect;
  317.                         repeat
  318.                             application.processmessages;
  319.                             connected_light.color:=$00ff0000+j;
  320.                             if Focused then
  321.                                 connected_light.show;
  322.                             inc(j,k);
  323.                             if j>255 then
  324.                                 k:=-1
  325.                             else if j<0 then
  326.                                 k:=1;
  327.                         until connected or network_timed_out;
  328.                     except
  329.                         on err:exception do
  330.                             begin
  331.                                 e:='exception when trying to connect to server : '+err.message;
  332.                                 f:=true;
  333.                             end;
  334.                     end;
  335.                     if network_timed_out then
  336.                         begin
  337.                             e:='network connection timed out';
  338.                             f:=true;
  339.                             network_timed_out:=false;
  340.                         end
  341.                     else
  342.                         begin
  343.                             network_enabled:=true;
  344.                             if send_request('play','Server wont play')>=[exit_ok] then
  345.                                 begin
  346.                                     connected_light.Color:=cllime;
  347.                                     if Focused then
  348.                                         connected_light.Show;
  349.                                     connect_to_server_button.Enabled:=false;
  350.                                     disconnect_from_server_button.enabled:=true;
  351.                                     get_integer('model',k);
  352.                                     scope_type:=k;
  353.                                     update_model_type;
  354.                                     scope_control.connect_group.enabled:=true;
  355.                                 end;
  356.                         end;
  357.                 end;
  358.         end;
  359.     if f then
  360.         begin
  361.             connect_to_server_button.Enabled:=true;
  362.             disconnect_from_server_button.enabled:=false;
  363.             connected_light.Color:=clred;
  364.             if Focused then
  365.                 connected_light.Show;
  366.             write_status_log_check(e);
  367.         end;
  368.     write_status_log_check('<< connect to server');
  369. end;
  370.  
  371. procedure tscope_network.close_network_connection;
  372. begin
  373.     if scope_connected then
  374.         begin
  375.             send_request_check('disconnect');
  376.             scope_network.scope_connected:=false;
  377.             send_request_check('bored');
  378.         end;
  379.     if scope_client.connected then
  380.         scope_client.Disconnect;
  381.     network_enabled:=false;
  382.     connected_light.Color:=clred;
  383.     if Focused then
  384.         connected_light.Show;
  385.     disconnect_from_server_button.enabled:=false;
  386.     connect_to_server_button.enabled:=true;
  387.     scope_control.change_panel(false);
  388.     scope_control.connect_group.enabled:=false;
  389. end;
  390.  
  391. function tscope_network.send_message(
  392.     message_string,
  393.     error_string:string)
  394.     :response_type;
  395. var
  396.     e,s,t:string;
  397.     done,
  398.     failed:boolean;
  399.     i:integer;
  400.  
  401.     function send
  402.         :response_type;
  403.     begin
  404.         write_status_log_check('send : >>');
  405.         result:=[exit_ok];
  406.         e:='i said '+message_string;
  407.         failed:=false;
  408.         if scope_client.connected then
  409.             begin
  410.                 message_string:=message_string;
  411.                 received_text:='';
  412.                 enable_network_timer(response_timeout);
  413.                 scope_client.writeln(message_string);
  414.                 repeat
  415.                     try
  416.                         application.processmessages;
  417.                         received_text:=scope_client.readln(
  418.                             crlf,read_fail_count,max_buffer_size);
  419.                     except
  420.                         on err:exception do
  421.                             begin
  422.                                 e:=e+' : but failed with : '+err.message;
  423.                                 scope_connected:=false;
  424.                                 connect_to_server_button.Enabled:=true;
  425.                                 disconnect_from_server_button.enabled:=false;
  426.                                 connected_light.Color:=clred;
  427.                                 if Focused then
  428.                                     connected_light.Show;
  429.                                 scope_client.disconnect;
  430.                                 failed:=true;
  431.                             end;
  432.                     end
  433.                 until network_timed_out or (received_text<>'') or failed;
  434.                 s:=trim(received_text);
  435.                 if network_timed_out or failed or (s='') then
  436.                     begin
  437.                         if network_timed_out then
  438.                             begin
  439.                                 e:=e+' : but timed out : ';
  440.                                 failed:=true;
  441.                                 network_timed_out:=false;
  442.                             end;
  443.                     end
  444.                 else if s<>'' then
  445.                     begin
  446.                         if pos('ok',s)=1 then
  447.                             begin
  448.                                 if pos('=',s)=3 then
  449.                                     begin
  450.                                         if pos('(',s)=4 then
  451.                                             begin
  452.                                                 s:=copy(s,5,length(s));
  453.                                                 if s[length(s)]=')' then
  454.                                                     begin
  455.                                                         s[length(s)]:=',';
  456.                                                         option_names.clear;
  457.                                                         option_values.Clear;
  458.                                                         done:=false;
  459.                                                         while not done do
  460.                                                             begin
  461.                                                                 i:=pos(',',s);
  462.                                                                 if i>0 then
  463.                                                                     begin
  464.                                                                         t:=copy(s,1,i-1);
  465.                                                                         s:=copy(s,i+1,length(s));
  466.                                                                         i:=pos('=',t);
  467.                                                                         option_names.Add(copy(t,1,i-1));
  468.                                                                         option_values.add(copy(t,i+1,length(t)));
  469.                                                                     end
  470.                                                                 else
  471.                                                                     done:=true;
  472.                                                             end;
  473.                                                     end
  474.                                                 else
  475.                                                     begin
  476.                                                         e:=e+' : but response incomplete : ';
  477.                                                         failed:=true;
  478.                                                     end;
  479.                                             end
  480.                                     end;
  481.                             end
  482.                         else if pos('fail',s)=1 then
  483.                             begin
  484.                                 e:=e+' : but response incorrect : ';
  485.                                 failed:=true;
  486.                             end
  487.                     end
  488.             end
  489.         else
  490.             begin
  491.                 e:=e+' : not connected, so reseting : ';
  492.                 connect_to_server_button.Enabled:=true;
  493.                 disconnect_from_server_button.enabled:=false;
  494.                 connected_light.Color:=clred;
  495.                 if Focused then
  496.                     connected_light.Show;
  497.                 scope_client.disconnect;
  498.                 failed:=true;
  499.             end;
  500.         if failed then
  501.             begin
  502.                 e:=e+' : '+error_string;
  503.                 with scope_control do
  504.                     begin
  505.                         ignore_event_north:=event_0;
  506.                         ignore_event_south:=event_0;
  507.                         ignore_event_west:=event_0;
  508.                         ignore_event_east:=event_0;
  509.                     end;
  510.                 result:=[exit_fail];
  511.             end;
  512.         write_status_log_check(e);
  513.         write_status_log_check('<< : send');
  514.     end;
  515.  
  516. begin
  517.     result:=send;
  518. end;
  519.  
  520. function tscope_network.send_request(
  521.     message_str,
  522.     error_str:string)
  523.     :response_type;
  524. begin
  525.     result:=send_message(message_str,error_str);
  526. end;
  527.  
  528. function tscope_network.send_request_check(
  529.     message_string:string)
  530.     :response_type;
  531. begin
  532.     result:=send_request(message_string,no_response);
  533. end;
  534.  
  535. function tscope_network.get_option_value(
  536.     option:string)
  537.     :string;
  538. var
  539.     i:integer;
  540. begin
  541.     i:=option_names.indexof(option);
  542.     if i>=0 then
  543.         result:=option_values[i]
  544.     else
  545.         result:='';
  546. end;
  547.  
  548. function tscope_network.get_float(
  549.             option:string;
  550.     var exit_result:double)
  551.     :boolean;
  552. var
  553.     s:string;
  554. begin
  555.     s:=get_option_value(option);
  556.     if s<>'' then
  557.         begin
  558.             exit_result:=strtofloat(s);
  559.             result:=true;
  560.         end
  561.     else
  562.         result:=false;
  563. end;
  564.  
  565. function tscope_network.get_integer(
  566.             option:string;
  567.     var exit_result:longint)
  568.     :boolean;
  569. var
  570.     s:string;
  571. begin
  572.     s:=get_option_value(option);
  573.     if s<>'' then
  574.         begin
  575.             exit_result:=strtoint(s);
  576.             result:=true;
  577.         end
  578.     else
  579.         result:=false;
  580. end;
  581.  
  582. function tscope_network.get_string(
  583.             option:string;
  584.     var exit_result:string)
  585.     :boolean;
  586. var
  587.     s:string;
  588. begin
  589.     s:=get_option_value(option);
  590.     if s<>'' then
  591.         begin
  592.             exit_result:=s;
  593.             result:=true;
  594.         end
  595.     else
  596.         result:=false;
  597. end;
  598.  
  599. function tscope_network.get_boolean(
  600.             option:string;
  601.     var exit_result:boolean)
  602.     :boolean;
  603. var
  604.     s:string;
  605. begin
  606.     s:=get_option_value(option);
  607.     if s<>'' then
  608.         begin
  609.             exit_result:=s='true';
  610.             result:=true;
  611.         end
  612.     else
  613.         result:=false;
  614. end;
  615.  
  616. procedure tscope_network.enable_network_timer(
  617.     timeout_interval:longint);
  618. begin
  619.     with network_timer do
  620.         begin
  621.             enabled:=false;
  622.             network_timed_out:=false;
  623.             interval:=timeout_interval;
  624.             enabled:=true;
  625.         end;
  626. end;
  627.  
  628. procedure tscope_network.network_timerTimer(
  629.     Sender: TObject);
  630. begin
  631.     network_timer.enabled:=false;
  632.     network_timed_out:=true;
  633. end;
  634.  
  635. procedure tscope_network.update_model_type;
  636. begin
  637.     with scope_control do
  638.         slew_group.visible:=true;
  639. end;
  640.  
  641.     { -------
  642.         logging
  643.         ------- }
  644.  
  645. procedure tscope_network.write_status_log(
  646.     e:string;
  647.     message_logging:boolean);
  648. var
  649.     s:string;
  650.     a,m:boolean;
  651. begin
  652.     if message_logging then
  653.         begin
  654.             a:=false;
  655.             m:=false;
  656.             if pos('>>',e)>0 then
  657.                 begin
  658.                     if not last_line_indented then
  659.                         inc(indented,2)
  660.                     else
  661.                         last_line_indented:=false;
  662.                     a:=true;
  663.                 end
  664.             else if pos('<<',e)>0 then
  665.                 begin
  666.                     if not last_line_unindented then
  667.                         dec(indented,2)
  668.                     else
  669.                         last_line_unindented:=false;
  670.                     m:=true;
  671.                 end;
  672.             s:=stringofchar(#32,indented)+e;
  673.             if a then
  674.                 begin
  675.                     inc(indented,2);
  676.                 end
  677.             else if m then
  678.                 begin
  679.                     dec(indented,2);
  680.                 end;
  681.             status_log.Lines.Add(s+#13);
  682.             scope_network.write_log(s);
  683.         end;
  684. end;
  685.  
  686. procedure tscope_network.write_status_log_check(
  687.     e:string);
  688. begin
  689.     if message_logging then
  690.         write_status_log(e,true);
  691. end;
  692.  
  693. Procedure tscope_network.init_log_file(
  694.     s:string);
  695. var
  696.     io:integer;
  697. begin
  698.     try
  699.         log_filename:=application_path+s;
  700.         {$I-}
  701.         assignfile(log_handle,log_filename);
  702.         {$I+}
  703.         io:=ioresult;
  704.         if io=0 then
  705.             begin
  706.                 rewrite(log_handle);
  707.                 writeln(log_handle,DateTimeToStr(now)+' : session started');
  708.                 close_log;
  709.             end
  710.         else
  711.             write_status_log_check('cant create log file : '+log_filename);
  712.     except
  713.         on err:exception do
  714.             begin
  715.                 write_status_log_check('failed to open log : '+err.message);
  716.             end;
  717.     end;
  718. end;
  719.  
  720. Procedure tscope_network.write_log(
  721.     e:string);
  722. var
  723.     io:integer;
  724. begin
  725.     if logging then
  726.         begin
  727.             try
  728.                 {$I-}
  729.                 assignfile(log_handle,log_filename);
  730.                 {$I+}
  731.                 io:=ioresult;
  732.                 if io=0 then
  733.                     begin
  734.                         append(log_handle);
  735.                         writeln(log_handle,FormatDateTime('hh:mm:ss.zzz',now)+' : '+e);
  736.                         close_log;
  737.                     end
  738.                 else
  739.                     write_status_log_check('cant open log : '+log_filename);
  740.             except
  741.                 on err:exception do
  742.                     begin
  743.                         write_status_log_check('failed to write to log : '+err.message);
  744.                         close_log;
  745.                     end
  746.             end;
  747.         end;
  748. end;
  749.  
  750. Procedure tscope_network.close_log;
  751. var
  752.     io:integer;
  753. begin
  754.     try
  755.         {$I-}
  756.         closefile(log_handle);
  757.         {$I+}
  758.         io:=ioresult;
  759.         if io<>0 then
  760.              write_status_log_check(
  761.             'failed to close : '+log_filename+' : '+inttostr(io));
  762.     except
  763.         on err:exception do
  764.             write_status_log_check('failed to close log : '+err.message);
  765.     end;
  766. end;
  767.  
  768.     { -------------
  769.         configuration
  770.         ------------- }
  771.  
  772. procedure tscope_network.load_settings;
  773. begin
  774.     ini_file:=tinifile.create(application_path+'client.ini');
  775.     with ini_file do
  776.         begin
  777.             server_ip_address:=ReadString('network','ip_address','127.0.0.1');
  778.             server_ip_edit.text:=server_ip_address;
  779.             logging:=ReadBool('network','logging',false);
  780.             if logging then
  781.                 disk_button.Font.style:=[fsbold]
  782.             else
  783.                 disk_button.font.style:=[];
  784.             message_logging:=ReadBool('network','message_logging',true);
  785.             if message_logging then
  786.                 messages_button.Font.style:=[fsbold]
  787.             else
  788.                 messages_button.font.style:=[];
  789.             { form }
  790.             scope.get_dimensions(scope_network,@dimensions,'network',ini_file);
  791.             left:=dimensions.form_left;
  792.             top:=dimensions.form_top;
  793.             visible:=readbool('network','visible',false);
  794.         end;
  795.     ini_file.free;
  796. end;
  797.  
  798. procedure tscope_network.save_settings;
  799. begin
  800.     with ini_file do
  801.         begin
  802.             writestring('network','ip_address',server_ip_address);
  803.             writebool('network','logging',logging);
  804.             writebool('network','message_logging',message_logging);
  805.             { form }
  806.             scope.find_vdu(scope_network,@dimensions);
  807.             scope.write_dimensions(@dimensions,left,top,'network',ini_file);
  808.             writebool('network','visible',visible);
  809.         end;
  810. end;
  811.  
  812.     { ------
  813.         events
  814.         ------ }
  815.  
  816. procedure tscope_network.FormShow(
  817.     Sender: TObject);
  818. begin
  819.     with dimensions do
  820.         begin
  821.             top:=form_top;
  822.             left:=form_left;
  823.         end;
  824. end;
  825.  
  826. procedure tscope_network.adjust;
  827. begin
  828.     with dimensions do
  829.         begin
  830.             form_top:=trunc(form_top/last_screen_height*current_height);
  831.             form_left:=trunc(form_left/last_screen_width*current_width);
  832.         end;
  833.     if visible then
  834.         show;
  835. end;
  836.  
  837. procedure tscope_network.check_visible_and_show_hide(
  838.     sender:tobject);
  839. begin
  840.     if visible then
  841.         hide_form
  842.     else
  843.         show_form;
  844.     scope.show_hide(sender,visible);
  845. end;
  846.  
  847. procedure tscope_network.hide_form;
  848. begin
  849.     with dimensions do
  850.         begin
  851.             form_top:=top;
  852.             form_left:=left;
  853.         end;
  854.     Visible:=false;
  855. end;
  856.  
  857. procedure tscope_network.show_form;
  858. begin
  859.     Visible:=true;
  860. end;
  861.  
  862. procedure Tscope_network.check_activate(
  863.     Sender: TObject);
  864. begin
  865.     scope.form_activate(scope_network,@dimensions);
  866. end;
  867.  
  868. procedure tscope_network.connect_to_server_buttonClick(
  869.     Sender: TObject);
  870. begin
  871.     connect_to_server;
  872. end;
  873.  
  874. procedure tscope_network.disconnect_from_server_buttonClick(
  875.     Sender: TObject);
  876. begin
  877.     if scope_client.connected then
  878.         begin
  879.             if scope_connected then
  880.                 scope_control.disconnect_from_scope;
  881.             send_request('bored','server wont go');
  882.         end;
  883.     close_network_connection;
  884. end;
  885.  
  886. procedure tscope_network.clear_log_buttonClick(
  887.     Sender: TObject);
  888. begin
  889.     status_log.Lines.Clear;
  890.     write_status_log_check('log cleared');
  891. end;
  892.  
  893. procedure tscope_network.messages_buttonClick(
  894.     Sender: TObject);
  895. begin
  896.     if not message_logging then
  897.         begin
  898.             message_logging:=true;
  899.             messages_button.font.style:=[fsbold];
  900.             write_status_log_check('messages enabled');
  901.         end
  902.     else
  903.         begin
  904.             messages_button.font.style:=[];
  905.             write_status_log_check('messages disabled');
  906.             message_logging:=false;
  907.         end;
  908. end;
  909.  
  910. procedure tscope_network.disk_buttonClick(
  911.     Sender: TObject);
  912. begin
  913.     with scope_network do
  914.         begin
  915.             if logging then
  916.                 begin
  917.                     logging:=false;
  918.                     disk_button.font.style:=[];
  919.                     write_status_log_check('logging disabled');
  920.                 end
  921.             else
  922.                 begin
  923.                     logging:=true;
  924.                     init_log_file('ntc-client.log');
  925.                     disk_button.font.style:=[fsbold];
  926.                     write_status_log_check('logging enabled');
  927.                 end;
  928.         end;
  929. end;
  930.  
  931. end.
  932.